﻿using System;
using System.Collections.Generic;
using System.Web;
using PayRoller.Code;
using System.Web.SessionState;
using System.Web.Profile;
using System.Web.UI.WebControls;
using HySoft.Cash.Business;
using HySoft.Cash.Structure;

namespace PayRoller.Member
{
    public class EmpUpt : MemberParent, IRequiresSessionState
    {
        // Fields
        protected Button Button1;
        protected Label lblTip;
        public string Sid = "";
        protected TextBox txtAddress1;
        protected TextBox txtAddress2;
        protected TextBox txtEmpName;
        protected TextBox txtOrgEmpSid;
        protected TextBox txtTaxFileNumber;

        // Methods
        protected void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (base.Request["Sid"].ToString().Trim() != "")
                {
                    this.Sid = base.Request["Sid"].ToString();
                    TempinfoBN obn = new TempinfoBN(this.Page);
                    TempinfoDT detail = obn.Get(Convert.ToInt32(this.Sid));
                    detail.EmpName = this.txtEmpName.Text;
                    detail.OrgEmpSid = this.txtOrgEmpSid.Text;
                    detail.TaxFileNumber = this.txtTaxFileNumber.Text;
                    detail.Address1 = this.txtAddress1.Text;
                    detail.Address2 = this.txtAddress2.Text;
                    if (obn.Edit(detail))
                    {
                        new OpeCommon().AddUptReport(Convert.ToInt32(this.Sid), "0003", Convert.ToInt32(base.OrgSid));
                        base.ClientScript.RegisterStartupScript(base.GetType(), "", "<script>alert('Success!');window.location='EmpList.aspx';</script>");
                    }
                    obn.Dispose();
                    obn = null;
                }
            }
            catch (Exception exception)
            {
                this.lblTip.Text = exception.Message;
            }
        }

        protected override void OnInit(EventArgs e)
        {
            base.CheckLogin();
            base.OnInit(e);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.Button1.Attributes.Add("onclick", "return Check();");
            if ((base.Request["Sid"] != null) && !this.Page.IsPostBack)
            {
                this.Sid = base.Request["Sid"].ToString();
                TempinfoBN obn = new TempinfoBN(this.Page);
                TempinfoDT odt = obn.Get(Convert.ToInt32(this.Sid));
                this.txtEmpName.Text = odt.EmpName;
                this.txtOrgEmpSid.Text = odt.OrgEmpSid;
                this.txtTaxFileNumber.Text = odt.TaxFileNumber;
                this.txtAddress1.Text = odt.Address1;
                this.txtAddress2.Text = odt.Address2;
                obn.Dispose();
                obn = null;
            }
        }

        // Properties
        protected HttpApplication ApplicationInstance
        {
            get
            {
                return this.Context.ApplicationInstance;
            }
        }

        protected DefaultProfile Profile
        {
            get
            {
                return (DefaultProfile)this.Context.Profile;
            }
        }
    }

}
